<html>
<head><meta charset="utf-8"><title>Confused about the traversals in rustc_lint · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html">Confused about the traversals in rustc_lint</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224163067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224163067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224163067">(Jan 27 2021 at 10:32)</a>:</h4>
<p>I don't understand how these traversals work. For example, in <a href="https://github.com/rust-lang/rust/blob/78e22069d018e83915201c8a218a0a94227f6420/compiler/rustc_lint/src/unused.rs#L100-L102">https://github.com/rust-lang/rust/blob/78e22069d018e83915201c8a218a0a94227f6420/compiler/rustc_lint/src/unused.rs#L100-L102</a> we don't visit the expression of a "return". How is the expression visited in this case? In my testing I can see that it is visited, but I can't figure out how.</p>



<a name="224164990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224164990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224164990">(Jan 27 2021 at 10:54)</a>:</h4>
<p>By visited, you mean that <code>f()</code> call will be linted in<code>return { f(); ... }</code>?</p>



<a name="224165104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224165104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224165104">(Jan 27 2021 at 10:55)</a>:</h4>
<p>Yes. Or more generally <code>&lt;e&gt;</code> in <code>return &lt;e&gt;</code>.</p>



<a name="224165182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224165182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224165182">(Jan 27 2021 at 10:56)</a>:</h4>
<p>There are a lot of similar tricky code in this traversal too. This is just one example. Interestingly it seems to visit all expressions somehow, even with all these early returns.</p>



<a name="224165196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224165196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224165196">(Jan 27 2021 at 10:56)</a>:</h4>
<p>That would be because lint itself isn't responsible for traversal. see code in <code>rustc_lint/src/late.rs</code> which invokes check methods.</p>



<a name="224165208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224165208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224165208">(Jan 27 2021 at 10:56)</a>:</h4>
<p>Oh!</p>



<a name="224165618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224165618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224165618">(Jan 27 2021 at 11:00)</a>:</h4>
<p>OK that makes sense. Thanks.</p>



<a name="224167178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Confused%20about%20the%20traversals%20in%20rustc_lint/near/224167178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Confused.20about.20the.20traversals.20in.20rustc_lint.html#224167178">(Jan 27 2021 at 11:16)</a>:</h4>
<p>If I understand this code correctly, I can't skip some nodes in my lint implementation because I have no control over the visitor, right? For example I can't skip some nodes. Let's say I do some checks when I see nested binops like <code>e1 &lt;op&gt; (e2 &lt;op&gt; e3)</code> and in some cases I want to avoid visiting <code>e1</code> because if I do that it'll give a false positive.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>